<?php
namespace app\index\controller;

use think\Controller;

class News extends Common
{
    public function _initialize()
    {
        parent::_initialize();
        $this->assign('active', '新闻咨询');
        $url = input('param.cid', 0) > 0 ? '/news/' . input('param.cid', 0) : '/news';
        $this->assign('nav_image', get_nav_img($url));
    }

    // 新闻中心页面
    public function index() {
        $cid = input('param.cid', 0);

        $news_cate = db('news_category')->select();
        $this->assign('news_cate', $news_cate);

        if ($cid == 0) {
            $cid = $news_cate[0]['id'];
        }

        $where['cate_id'] = $cid;
        $news = db('news')->where($where)->order('id desc')->paginate(6);

        $this->assign('news', $news);
        $this->assign('cid', $cid);
        return view();
    }

    // 新闻详情
    public function news_details() {
        $id = input('param.id');
        $news = db('news')->alias('n')
            ->field('n.*, nc.content')
            ->join('osl_news_content nc', 'n.id = nc.news_id', 'LEFT')
            ->where('n.id', $id)
            ->find();
        $this->assign('news', $news);
        return view();
    }
}
